package com.Yukiha.gachamod.ysm;

import com.Yukiha.gachamod.Data.GachaSavedData;
import net.minecraft.server.level.ServerLevel;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Set;
import java.util.UUID;



public class YsmAuthorizationHandler {


    /**
     * 授权玩家获得某个模型
     */
    public static void authorize(ServerLevel level, UUID uuid, String modelId) {
        GachaSavedData data = GachaSavedData.get(level);
        data.addModel(uuid, modelId);
        data.setDirty(); // 标记为需要保存
    }

    /**
     * 移除玩家某个模型授权
     */
    public static void unauthorize(UUID uuid, String modelId) {
        // 默认从主世界获取保存数据
        ServerLevel level = getPrimaryLevel();
        GachaSavedData data = GachaSavedData.get(level);
        data.removeModel(uuid, modelId);
        data.setDirty();
    }

    /**
     * 检查玩家是否已获得某个模型
     */
    public static boolean isAuthorized(UUID uuid, String modelId) {
        ServerLevel level = getPrimaryLevel();
        GachaSavedData data = GachaSavedData.get(level);
        return data.getModels(uuid).contains(modelId);
    }


    private static ServerLevel getPrimaryLevel() {
        return net.minecraftforge.server.ServerLifecycleHooks.getCurrentServer().overworld();
    }

    public static Set<String> getAuthorizedModels(UUID uuid) {
        return GachaSavedData.get(getPrimaryLevel()).getModels(uuid);


    }
}
